import allure
from appium.webdriver.common.appiumby import AppiumBy

from src.day42.PO.setup_page import SetupPage
from src.day42.PO.xueqiu import XueQiu


class SelectedPage(XueQiu):
    __RECOVERY=(AppiumBy.ID, 'com.xueqiu.android:id/restore_default')
    __PRICE_BUTTON=(AppiumBy.XPATH, '//*[@text="最新价"]')
    __GET_PRICE=(AppiumBy.XPATH,'//*[@resource-id="com.xueqiu.android:id/content_recycler"]//*[@resource-id="com.xueqiu.android:id/item_layout" or @resource-id="com.xueqiu.android:id/portfolio_currentPrice"]/../../child::*[1]/child::*[1]')
    __SETUP=(AppiumBy.ID, "com.xueqiu.android:id/portfolio_setting")
    def get_latest_prices(self):
        with allure.step("点击一次恢复"):
            try:
                self.find_and_click(*self.__RECOVERY)
            except Exception as e:
                print("没有恢复按钮")
        with allure.step("点击最新价按钮"):
            self.find_and_click(*self.__PRICE_BUTTON)
        with allure.step("获取最新价格"):
            eles = self.finds(*self.__GET_PRICE)
            prices = [float(el.text) for el in eles]
            return prices
    def goto_setup_page(self):
        with allure.step("# 点击【设置】图标"):
            self.find_and_click(*self.__SETUP)
        return SetupPage(self.driver)
